<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2020/10/09 11:56
 * Desc: 合同处理
 */
class Model_Api_V2_Contract {

    /**
     * @function 根据订单id获取对应的合同信息
     * @param $orderid
     * @return mixed
     */
    public static function get_order_contract($orderid)
    {
        $orderDetail=DB::select()->from('member_order')->where('id','=',$orderid)->execute()->current();
        if($orderDetail)
        {
            $result['status']=true;
            $result['msg']='获取成功';
            $contract=DB::select()->from('contract')->where('id','=',$orderDetail['contract_id'])->execute()->current();
            if(!$contract['type'] || ($contract['type'] && $contract['type']==1))
            {
                $data['title']=$contract['title'];
                $data['content']=$contract['content'];
                $data['url']='';
                $data['extension']='';
                $result['data']=$data;
            }else if($contract['type'] && $contract['type']==2){
                $contractsup=DB::select()->from('contract_supervise')->where('order_id','=',$orderid)->execute()->current();
                if($contractsup)
                {
                    $data['title']=$contractsup['contractnName'];
                    $data['content']='';
                    $data['url']=$contractsup['fileURL'];
                    $data['extension']='pdf';
                }else{
                    $data['title']='';
                    $data['content']='';
                    $data['url']='';
                    $data['extension']='';
                }
                $result['data']=$data;
            }else{
                $result['status']=false;
                $result['msg']='合同不存在';
            }
        }else{
            $result['status']=false;
            $result['msg']='合同不存在';
        }

        return $result;
    }

}